package cn.edu.neusoft.zengweidong707.neufood.activity;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import java.util.List;

import cn.edu.neusoft.zengweidong707.neufood.R;
import cn.edu.neusoft.zengweidong707.neufood.adapter.UserOrderAdapter;
import cn.edu.neusoft.zengweidong707.neufood.bean.UserOrderBean;
import cn.edu.neusoft.zengweidong707.neufood.listener.ListListener;
import cn.edu.neusoft.zengweidong707.neufood.model.UserModel;

public class UserOrderActivity extends BaseActivity {
    private UserModel model;
    private RecyclerView recyclerView;
    private List<UserOrderBean> list;
    private ListListener<UserOrderBean> listListener;
    private UserOrderAdapter userOrderAdapter;
    private LinearLayoutManager linearLayoutManager;
    private Button btn_back;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_user_order);
        recyclerView = (RecyclerView)findViewById(R.id.order_rec);
        linearLayoutManager = new LinearLayoutManager(UserOrderActivity.this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        btn_back = (Button) findViewById(R.id.ord_back);
    }

    @Override
    void initEvent() {
        listListener = new ListListener<UserOrderBean>() {
            @Override
            public void onResponse(List<UserOrderBean> userOrderBeans) {
                list = userOrderBeans;
                userOrderAdapter = new UserOrderAdapter(UserOrderActivity.this, list);
                recyclerView.setAdapter(userOrderAdapter);
            }

            @Override
            public void onFail(String msg) {
                showToast(msg);
            }
        };

        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    void initData() {
        int uid = Integer.parseInt(getUserid().toString());
        model = new UserModel();
        model.getOrderByUserid(uid, listListener);
    }
}
